package com.springboot.frame.starter.pay.v3;

import lombok.Data;
import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author liheng
 * @ClassName V3
 * @Description
 * @date 2021-09-01 11:09
 */
@Data
public class V3 {
    /**
     * 获取 API 密钥
     *
     * @return API密钥
     */
    private String apiKey;
    /**
     * 秘钥路径，apiclient_key.pem
     */
    private String privateKeyPath;
    /**
     * 商户证书序列号
     */
    private String  mchSerialNo;

    /**
     * 支付回调地址--服务商
     *
     * @return
     */
    private String facilNotifyUrl;


    public InputStream getPrivateKeyStream() {
        // 需要证书释放
        byte[] certData;
        InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(this.privateKeyPath);
        try {
            certData = IOUtils.toByteArray(certStream);
            certStream.close();
        } catch (IOException e) {
            throw new RuntimeException("私钥文件未找到");
        }
        return new ByteArrayInputStream(certData);
    }
}
